using System.Web.Routing;
using BlogExample.Core.Services;
using FubuMVC.Core.Runtime;
using FubuMVC.StructureMap;
using StructureMap;

namespace BlogExample.Config
{
	public class FubuStructureMapBootstrapper : IBootstrapper
	{
		private readonly RouteCollection _routes;

		private FubuStructureMapBootstrapper(RouteCollection routes)
		{
			_routes = routes;
		}

		public void BootstrapStructureMap()
		{
			UrlContext.Reset();

			ObjectFactory.Initialize(x =>
			{
				x.Scan(y =>
					{
						y.AssemblyContainingType<IDisplayService>();
						y.WithDefaultConventions();
					});
				x.For<IDisplayStrategy>().Use<InstructorDisplayStrategy>();
			}
		);

			BootstrapFubu(ObjectFactory.Container, _routes);
		}

		public static void BootstrapFubu(IContainer container, RouteCollection routes)
		{
			var bootstrapper = new StructureMapBootstrapper(container, new BlogExampleFubuRegistry());
			bootstrapper.Bootstrap(routes);
		}

		public static void Bootstrap(RouteCollection routes)
		{
			new FubuStructureMapBootstrapper(routes).BootstrapStructureMap();
		}
	}
}